package com.museum.core.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * Created with IntelliJ IDEA.
 * User: 王瑞文
 * Date: 2020/9/16
 * Time: 16:36
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Autowired
    private LoginInterceptor loginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").
               // excludePathPatterns("/sendSms","/checkSms","/sms/loginSend","/sms/registerSend","/user/login","/user/register","/permission/getAllPermission");
                excludePathPatterns("/sendSms","/checkSms","/sms/loginSend","/sms/registerSend","/user/login","/user/register","/user/logout","/user/loginById","/area/**");
                //excludePathPatterns("/sms/loginSend","/sms/registerSend","/user/login","/user/register");
    }
    @Bean
    public CorsFilter corsFilter() {
        System.out.println("跨域配置生效");
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedOrigin("*");
        config.setAllowCredentials(true);
        config.addAllowedMethod("*");
        config.addAllowedHeader("*");
        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        configSource.registerCorsConfiguration("/**", config);
        return new CorsFilter(configSource);
    }

}
